@tool
class_name AvoidContextBehavior
extends BaseContextBehavior

#region 属性
@export var avoid_radius:float = 40
#endregion
#region 字段
#endregion
#region 信号
#endregion

#region 基类方法
func init_context(steering_component:SteeringComponent,resolution_radio:int):
	super.init_context(steering_component,resolution_radio)
func get_interest(entity:CharacterEntity,directions:Array[Vector2]) -> Array[float]:
	interest = []
	interest.resize(directions.size())
	return interest
func get_danger(entity:CharacterEntity,directions:Array[Vector2]) -> Array[float]:
	danger = []
	danger.resize(directions.size())
	var detector = entity.get_detector(GameEnum.DetectorType.Obstacle)
	if not detector:
		return danger
	var obstacle_closest_point:Array[Vector2] = detector.obstacle_closest_point.filter(func (x):return (x - entity.global_position).length() <= avoid_radius)
	for i in range(directions.size()):
		danger[i] = 0
		for j in range(obstacle_closest_point.size()):
			var point = obstacle_closest_point[j]
			var distance = (point - entity.get_pos()).length()
			var cos_theta = (point - entity.get_pos()).normalized().dot(directions[i])
			if cos_theta > 0:
				danger[i] += 1/distance * cos_theta * sensitive
		if entity.test_move(entity.global_transform,entity.get_entity_data().get_scale_move_speed() * directions[i] * steering_component.update_dalay):
			danger[i] += 1/(entity.get_entity_data().get_scale_move_speed() * steering_component.update_dalay) * sensitive
	return danger
#endregion
#region 公共方法
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _draw() -> void:
	super._draw()
#endregion

